package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysOrderTrend;
import com.ruoyi.system.service.ISysOrderTrendService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单趋势Controller
 * 
 * @author ruoyi
 * @date 2022-12-20
 */
@Controller
@RequestMapping("/system/trend")
public class SysOrderTrendController extends BaseController
{
    private String prefix = "system/trend";

    @Autowired
    private ISysOrderTrendService sysOrderTrendService;

    @RequiresPermissions("system:trend:view")
    @GetMapping()
    public String trend()
    {
        return prefix + "/trend";
    }

    /**
     * 查询订单趋势列表
     */
    @RequiresPermissions("system:trend:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysOrderTrend sysOrderTrend)
    {
        startPage();
        List<SysOrderTrend> list = sysOrderTrendService.selectSysOrderTrendList(sysOrderTrend);
        return getDataTable(list);
    }

    /**
     * 导出订单趋势列表
     */
    @RequiresPermissions("system:trend:export")
    @Log(title = "订单趋势", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysOrderTrend sysOrderTrend)
    {
        List<SysOrderTrend> list = sysOrderTrendService.selectSysOrderTrendList(sysOrderTrend);
        ExcelUtil<SysOrderTrend> util = new ExcelUtil<SysOrderTrend>(SysOrderTrend.class);
        return util.exportExcel(list, "订单趋势数据");
    }

    /**
     * 新增订单趋势
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存订单趋势
     */
    @RequiresPermissions("system:trend:add")
    @Log(title = "订单趋势", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysOrderTrend sysOrderTrend)
    {
        return toAjax(sysOrderTrendService.insertSysOrderTrend(sysOrderTrend));
    }

    /**
     * 修改订单趋势
     */
    @RequiresPermissions("system:trend:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysOrderTrend sysOrderTrend = sysOrderTrendService.selectSysOrderTrendById(id);
        mmap.put("sysOrderTrend", sysOrderTrend);
        return prefix + "/edit";
    }

    /**
     * 修改保存订单趋势
     */
    @RequiresPermissions("system:trend:edit")
    @Log(title = "订单趋势", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysOrderTrend sysOrderTrend)
    {
        return toAjax(sysOrderTrendService.updateSysOrderTrend(sysOrderTrend));
    }

    /**
     * 删除订单趋势
     */
    @RequiresPermissions("system:trend:remove")
    @Log(title = "订单趋势", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysOrderTrendService.deleteSysOrderTrendByIds(ids));
    }
}
